# -*- shell-script -*-

# 00minimal - Default hardware database routines and variables.

# This file is part of the Linux lsvpd package.

# (C) Copyright IBM Corp. 2002, 2003, 2004, 2005

# Maintained by  Martin Schwenke <martins@au.ibm.com>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    
# $Id: 00minimal,v 1.1 2006/04/11 18:38:28 emunson Exp $

# This module is always loaded.
true || return 0

######################################################################

vardir="/var/lib/lsvpd"
db_prefix="db"
db_default="${vardir}/${db_prefix}"
[ -n "$db" ] || db="$db_default"

######################################################################

db_set_subdir_vars_hook ()
{
    local i
    for i in $db_subdir_vars_hooks ; do
	$i
    done
}

db_subdir_vars_hooks="db_set_subdir_vars_basic"

db_set_subdir_vars_basic ()
{
    db_bus_subdir="bus"
    db_bus_dir="${db}/${db_bus_subdir}"
    db_bus_root="$db_bus_dir"

    db_os_subdir="linux"
    db_os_dir="${db}/${db_os_subdir}"

    db_misc_dir="${db_os_dir}/misc"
    db_proc_dir="${db_misc_dir}/proc"
    db_uname_dir="${db_misc_dir}/uname"

    db_state_subdir="state"
    db_state_dir="${db}/${db_state_subdir}"

    db_tmp_subdir="tmp"
    db_tmp_dir="${db}/${db_tmp_subdir}"
}

# May get re-run for a different value of $db later.
db_set_subdir_vars_hook

######################################################################

dynamic_vpd_hooks=""

run_dynamic_vpd_hooks ()
{
    for i in $dynamic_vpd_hooks ; do
	$i
    done
}

linux_dynamic_vpd="linux,dynamic-vpd"

case "$LSVPD_FORCE_DYNAMIC" in
    (true|false) :                         ;;
    (*)          LSVPD_FORCE_DYNAMIC=false ;;
esac

on_live_system ()
{
    [ "$db" = "$db_default" ]
}

should_show_dynamic_vpd ()
{
    # $EUID is a bashism
    should_show_cached_vpd || can_cache_vpd
}

can_cache_vpd ()
{
    [ "$EUID" -eq 0 ] && on_live_system
}

should_show_cached_vpd ()
{
    $LSVPD_FORCE_DYNAMIC
}

node_contains_dynamic_vpd ()
{
    local node="$1"

    [ -e "${node}/${linux_dynamic_vpd}" ]
}
